﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Z2.Core
{

    public class FloatingText : IDraw
    {

        private string m_text;
        private Vector2 m_position;
        private Color m_color;
        private ActionTimer m_fadeout;
        private ActionTimer m_tick;

        public FloatingText(string text, Vector2 position)
        {
            this.m_text = text;
            this.m_position = position;
            this.Color = Color.White;
            this.m_fadeout = new ActionTimer(2000D);
            this.m_tick = new ActionTimer(10);
            this.m_tick.Enabled = true;
            this.m_fadeout.Enabled = true;
        }

        public string Text
        {
            get { return this.m_text; }
            set { this.m_text = value; }
        }

        public Color Color
        {
            get { return this.m_color; }
            set { this.m_color = value; }
        }

        #region IDraw Members

        public void Update()
        {
            if (this.m_tick.Now())
            {
                this.m_position.Y -= 0.8F;
                if (this.m_color.A - 4 > 1) this.m_color.A -= 4; else this.m_color.A = 0;
            }
            if (this.m_fadeout.Now())
            {
                World.Current.RemoveDraw(this);
            }
        }

        public void Draw(SpriteBatch batch)
        {
            batch.DrawString(
                SpriteManager.Instance.GenericFont, 
                this.m_text, 
                Vector2.Add(Camera.Instance.Position, this.m_position), 
                this.m_color, 
                0F,  // rotation
                Vector2.Zero, 
                1F, // scale
                SpriteEffects.None, 
                1F); // depth
        }

        public void DrawLight(SpriteBatch batch)
        {
        }

        #endregion
    }
}
